package com.ruoyi.system.service.impl.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CoTestMechatype;
import com.ruoyi.system.service.ICoTestMechatypeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 机构类型管理Controller
 * 
 * @author 冬木逢春
 * @date 2022-06-19
 */
@Controller
@RequestMapping("/system/MechaType")
public class CoTestMechatypeController extends BaseController
{
    private String prefix = "system/MechaType";

    @Autowired
    private ICoTestMechatypeService coTestMechatypeService;

    @RequiresPermissions("system:MechaType:view")
    @GetMapping()
    public String MechaType()
    {
        return prefix + "/MechaType";
    }

    /**
     * 查询机构类型管理列表
     */
    @RequiresPermissions("system:MechaType:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CoTestMechatype coTestMechatype)
    {
        startPage();
        List<CoTestMechatype> list = coTestMechatypeService.selectCoTestMechatypeList(coTestMechatype);
        return getDataTable(list);
    }

    /**
     * 导出机构类型管理列表
     */
    @RequiresPermissions("system:MechaType:export")
    @Log(title = "机构类型管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CoTestMechatype coTestMechatype)
    {
        List<CoTestMechatype> list = coTestMechatypeService.selectCoTestMechatypeList(coTestMechatype);
        ExcelUtil<CoTestMechatype> util = new ExcelUtil<CoTestMechatype>(CoTestMechatype.class);
        return util.exportExcel(list, "机构类型管理数据");
    }

    /**
     * 新增机构类型管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存机构类型管理
     */
    @RequiresPermissions("system:MechaType:add")
    @Log(title = "机构类型管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CoTestMechatype coTestMechatype)
    {
        return toAjax(coTestMechatypeService.insertCoTestMechatype(coTestMechatype));
    }

    /**
     * 修改机构类型管理
     */
    @RequiresPermissions("system:MechaType:edit")
    @GetMapping("/edit/{mechaId}")
    public String edit(@PathVariable("mechaId") Long mechaId, ModelMap mmap)
    {
        CoTestMechatype coTestMechatype = coTestMechatypeService.selectCoTestMechatypeByMechaId(mechaId);
        mmap.put("coTestMechatype", coTestMechatype);
        return prefix + "/edit";
    }

    /**
     * 修改保存机构类型管理
     */
    @RequiresPermissions("system:MechaType:edit")
    @Log(title = "机构类型管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CoTestMechatype coTestMechatype)
    {
        return toAjax(coTestMechatypeService.updateCoTestMechatype(coTestMechatype));
    }

    /**
     * 删除机构类型管理
     */
    @RequiresPermissions("system:MechaType:remove")
    @Log(title = "机构类型管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(coTestMechatypeService.deleteCoTestMechatypeByMechaIds(ids));
    }
}
